import {Component, OnInit} from '@angular/core';
import {config} from '../smartadmin.config';
import { JsonApiService } from "app/core/api/json-api.service"; //http请求配置引入

declare var $: any;
@Component({
  	selector: 'sa-batch-updata',
  	templateUrl: './batch-updata.component.html',
  	styleUrls:['./batch-updata.css']
})
export class BatchUpdataComponent implements OnInit{
  	isActivated:boolean;
	upgradeType:string = 'on';//离线,在线状态切换
	upgradeOnlineList:any = [];//在线升级数据
	upgradeOfflineList:any = [];//离线升级数据
	upgradeOnlineTotal:number = 0;//在线升级总数
	upgradeOfflineTotal:number = 0;//离线升级总数
  	constructor(private jsonApiService: JsonApiService) {}

  	ngOnInit() {
  		this.initUpgradeOnline();
		this.initUpgradeOffline();
  	}
  	//初始化在线升级数据
	initUpgradeOnline(){
		this.jsonApiService.http('devicemonitor/monitorforupgradeonline.html',null).subscribe(data => {
			if(data.success){
				this.upgradeOnlineList = data.data;
				this.upgradeOnlineTotal = data.data.length;
			}else{
				this.jsonApiService.message(data.message);
			}
		})
	}
	//初始化离线升级数据
	initUpgradeOffline(){
		this.jsonApiService.http('devicemonitor/monitorforupgradeOffline.html',null).subscribe(data => {
			if(data.success){
				this.upgradeOfflineList = data.data;
				this.upgradeOfflineTotal = data.data.length;
			}else{
				this.jsonApiService.message(data.message);
			}
		})
	}
	//刷新
	upgradeRefresh(){
		this.initUpgradeOnline();
		this.initUpgradeOffline();
	}
	//打开,关闭事件回调
  	onToggle() {
  		if(!this.isActivated){
  			this.upgradeRefresh();
  		}
    	this.isActivated = !this.isActivated
  	} 
}
